package cn.pxxy.util;

import cn.pxxy.domain.User;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

public class ControllerUtil {
    private final static String userKey = "admin";
    private ControllerUtil(){}
    public static User getCurrentUser(){
        HttpServletRequest request = ((ServletRequestAttributes)(RequestContextHolder.currentRequestAttributes())).getRequest();
        return (User)request.getSession(true).getAttribute(userKey);
    }
    public static void setUserIntoSession(User user){
        HttpServletRequest request = ((ServletRequestAttributes)(RequestContextHolder.currentRequestAttributes())).getRequest();
        request.getSession(true).setAttribute(userKey,user);
    }
}
